﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TAP04
    {

        public TAP04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAPFOLGE();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateAPFOLGE(dwMaster,app.company, 0);
            string key = KEY;
            KEY = "";
            KEY = key;
            base.OnSave();
        }

        public override void LOADBYAUF()
        { 
            if (ORDERNUM.Length < 11)
                return;
            dwData = TMV.TBMain.NewRow();
            dwData["APFMANDANT"] = app.Mandant;
            dwData["APFANRKRS"] = "AND APFANRKRS= '" + ORDERNUM.Substring(0, 2) + "'";
            dwData["APFALFDNR"] = "AND APFALFDNR= '" + ORDERNUM.Substring(2, 6) + "'";
            dwData["APFAFOLGE"] = "AND APFAFOLGE= '" + ORDERNUM.Substring(8, 3) + "'";
            SResult = TMV.QAPF09(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        } 
        public override void OnAGANGChg(string value)
        {
            if (!IsEdit)
                return;
            if (AGANG.Length < 15)
                return;
            TMV.APFKSTKRS = AGANG.Substring(0, 2);
            TMV.APFKST = AGANG.Substring(2, 4);
            TMV.APFAGANG = AGANG.Substring(6, 15);
            TMV.APFBZAGANG= AGANG.Substring(21).Trim().PadRight(60);
            base.OnAGANGChg(value);
        }

    }
}
